package com.niiwoo.civet.user.service.local.sms.impl;

import com.niiwoo.civet.user.constants.LoginAccountErrorCode;
import com.niiwoo.civet.user.dto.request.RefreshSMSCodeRequestDTO;
import com.niiwoo.civet.user.enums.UserSMSTypeEnum;
import com.niiwoo.civet.user.service.local.UserLoginAccountService;
import com.niiwoo.civet.user.service.local.sms.LimitedSMSSender;
import com.niiwoo.tripod.base.component.PrivacyMasks;
import com.niiwoo.tripod.provider.exception.BizException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class LoginSMSSender extends LimitedSMSSender {

    @Autowired
    UserLoginAccountService userLoginAccountService;

    @Autowired
    PrivacyMasks privacyMasks;


    @Override
    protected void innerBeforeSend(RefreshSMSCodeRequestDTO requestDTO) {
        if (!userLoginAccountService.isExists(privacyMasks.encryptPrivacy(requestDTO.getLoginMobileNo()))) {
            throw new BizException(LoginAccountErrorCode.USERS_NOT_EXIST);
        }
    }

    @Override
    protected String innerContentTemplate() {
        return LOGIN_TEMPLATE;
    }


    @Override
    protected UserSMSTypeEnum getType() {
        return UserSMSTypeEnum.LOGIN;
    }
}
